<template>
  <div class="app-container">
    <div class="login">
      <div class="leftcard">
        <div class="letcolor"></div>
      </div>
      <div class="rightcard">
        <div class="rightcard-top">
          <i class="iconfont1">&#xe636;</i>
          <h2>欢迎</h2>
        </div>
        <div class="white">
          <div class="form-control">
            <span class="font-i">
              <i class="iconfont">&#xe614;</i>
            </span>
            <input type="text" required="" v-model.trim="mobilePhone" maxlength="11" />
            <label>
              <span style="transition-delay: 0ms">手</span><span style="transition-delay: 50ms">机</span><span style="transition-delay: 100ms">号</span><span style="transition-delay: 150ms">码</span>
            </label>
            <p class="tips">请输入手机号</p>
          </div>
          <div class="form-control">
            <span class="font-i">
              <i class="iconfont">&#xe640;</i>
            </span>
            <input type="password" required="" v-model.trim="password" />
            <label>
              <span style="transition-delay: 0ms">账</span><span style="transition-delay: 50ms">号</span><span style="transition-delay: 100ms">密</span><span style="transition-delay: 150ms">码</span>
            </label>
            <p class="tips">请输入密码</p>
          </div>
          <!-- <div class="white"></div> -->
          <!-- <button class="signin">登录</button> -->
          <button @click="getSign">
            <!-- 按钮 -->
            <div class="svg-wrapper-1">
              <div class="svg-wrapper">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
                  <path fill="none" d="M0 0h24v24H0z"></path>
                  <path fill="currentColor" d="M1.946 9.315c-.522-.174-.527-.455.01-.634l19.087-6.362c.529-.176.832.12.684.638l-5.454 19.086c-.15.529-.455.547-.679.045L12 14l6-8-8 6-8.054-2.685z"></path>
                </svg>
              </div>
            </div>
            <span>登录</span>
          </button>
          <span class="register" @click="register">没有账号?<span class="registers"> 立刻注册</span></span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getLoginAPI } from '@/api/LoginAPI'
export default {
  created() {},
  data() {
    return {
      mobilePhone: '',
      password: '',
      tag: ''
    }
  },
  methods: {
    register() {
      this.$router.replace('/register')
    },
    getSign() {
      const phone =
        /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
      if (
        this.mobilePhone.length === 11 &&
        (this.password.length < 18) & (this.password.length >= 6)
      ) {
        if (phone.test(this.mobilePhone)) {
          this.StudentLogin()
        } else {
          this.$message({
            showClose: true,
            message: '登录失败',
            type: 'error'
          })
        }
      } else {
        this.$message({
          showClose: true,
          message: '登录失败',
          type: 'error'
        })
      }
    },
    async StudentLogin() {
      const { data: res } = await getLoginAPI(this.mobilePhone, this.password)
      if (res.code === 0) {
        this.$message({
          showClose: true,
          message: '登录成功',
          type: 'success'
        })
        localStorage.setItem('tag', res.data.tag)
        localStorage.setItem('id', res.data.id)
        localStorage.setItem('mobilePhone', res.data.mobilePhone)
        localStorage.setItem('username', res.data.username)
        this.$router.replace('/typing-game')
      } else {
        this.$message({
          showClose: true,
          message: '登录失败',
          type: 'error'
        })
      }
    }
  },
  components: {}
}
</script>
<style lang="less" scoped>
.register {
  cursor: pointer;
  transition: 0.5s;
  position: relative;
  left: 7vw;
  bottom: 4.5vh;
}
.registers {
  transition: 0.5s;
}
.register:hover .registers{
  color: #032B73;
}
html {
  font-family: 'Orbitron', sans-serif;
}
@font-face {
  font-family: 'iconfont'; /* Project id 3771308 */
  src: url('//at.alicdn.com/t/c/font_3771308_tp69a8l3uv.woff2?t=1668481571675')
      format('woff2'),
    url('//at.alicdn.com/t/c/font_3771308_tp69a8l3uv.woff?t=1668481571675')
      format('woff'),
    url('//at.alicdn.com/t/c/font_3771308_tp69a8l3uv.ttf?t=1668481571675')
      format('truetype');
}

.iconfont {
  font-family: 'iconfont' !important;
  font-size: 25px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -webkit-text-stroke-width: 0.2px;
  -moz-osx-font-smoothing: grayscale;
}

.iconfont1 {
  font-family: 'iconfont' !important;
  font-size: 40px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -webkit-text-stroke-width: 0.2px;
  -moz-osx-font-smoothing: grayscale;
}

.app-container {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  // background: linear-gradient(to bottom right, #09C6F9,#045DE9);
  // border-radius: 50%;169
  background-color: #032b73;
}
.login {
  width: 65%;
  height: 70vh;
  // background-color: aqua;
  box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;
  border-radius: 30px;
  background-color: white;
}
.login .leftcard {
  // display: inline-block;
  width: 60%;
  height: 100%;
  // background-color: #39d5ff;
  float: left;
  // background: #e0e0e0;
  // box-shadow: 15px 15px 30px #bebebe, -15px -15px 30px #ffffff;
  background: url(../assets/svg.png) no-repeat;
  border-radius: 30px 0 0 30px;
  background-size: 100% 100%;
}

.rightcard-top {
  text-align: center;
  margin-top: 4rem;
}
.rightcard-top h2 {
  font-size: 35px;
  margin-top: 20px;
}
.login .rightcard {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  width: 35%;
  height: 100%;
  // background-color: #8effc1;
  float: right;
  // border-radius: 30px;
  // background: #e0e0e0;
  // box-shadow: 0px 2px 8px #bebebe;
  // background: linear-gradient(to bottom right, #09c6f9, #045de9);
  // background: linear-gradient(to bottom right, #022085,#354ea2,#4169E1);
  border-radius: 0 10px 10px 0;
}
.form-control {
  position: relative;
  margin: 20px 0 50px 0px;
  width: 190px;
}

.form-control input {
  background-color: transparent;
  border: 0;
  border-bottom: 2px black solid;
  display: block;
  width: 100%;
  padding: 30px 0 2px 0;
  font-size: 18px;
  color: black;
}
.font-i {
  position: relative;
  top: 55px;
  right: 35px;
}
.tips {
  display: none;
  color: red;
}

.form-control input:focus,
.form-control input:valid {
  outline: 0;
  border-bottom-color: black;
}

.form-control label {
  position: absolute;
  top: 15px;
  left: 0;
  pointer-events: none;
}

.form-control label span {
  display: inline-block;
  font-size: 19px;
  min-width: 5px;
  color: black;
  transition: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  font-weight: 900;
}

.form-control input:focus + label span,
.form-control input:valid + label span {
  color: black;
  transform: translateY(-30px);
}
// .signin {
//   width: 180px;
//   height: 30px;
//   margin-top: 30px;
// }
.white {
  // height: 100px;
  // padding: 105px;
  margin-bottom: 80px;
}

// ---按钮样式---
button {
  font-family: inherit;
  font-size: 16px;
  background: royalblue;
  color: white;
  padding: 0.5em 1em;
  padding-left: 0.9em;
  display: flex;
  align-items: center;
  border: none;
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.2s;
  margin-top: 50px;
  cursor: pointer;
}

button span {
  display: block;
  margin-left: 0.3em;
  transition: all 0.3s ease-in-out;
}

button svg {
  display: block;
  transform-origin: center center;
  transition: transform 0.3s ease-in-out;
}

button:hover .svg-wrapper {
  animation: fly-1 0.6s ease-in-out infinite alternate;
}

button:hover svg {
  transform: translateX(1.2em) rotate(45deg) scale(1.1);
}

button:hover span {
  transform: translateX(5em);
}

button:active {
  transform: scale(0.95);
}

@keyframes fly-1 {
  from {
    transform: translateY(0.1em);
  }

  to {
    transform: translateY(-0.1em);
  }
}
.image {
  width: 300px;
  height: 80px;
  // margin: 0 auto;
}
</style>
